home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 1.iso / desktop / papcw10.zip / ROOT.PRG < prev    next >
Text File  |  1995-01-04  |  644b  |  31 lines

  1. ; calculate root of x^3 - (6 * x^2) + (11 * x) - 1 = 0 using Newton's method
  2. ; correct answer is 0.0958
  3. LBL findroot
  4. E-10 0 sto         ; tolerance
  5. 0.9                ; initial guess
  6. 100.00001 1 sto    ; loop counter for max iterations
  7. LBL loop
  8. DUP DUP XEQ f OVER XEQ fprime / -  ; calculate x'
  9. DUP ROT -
  10. ABS
  11. 0 RCL <=
  12. GTO OK
  13. DROP
  14. 1 DSE
  15. GTO loop
  16. PUTS "No convergence after 100 iterations\n"
  17. RTN
  18. LBL OK
  19. DROP
  20. PUTS "Answer = " 0 WIDTH 4 FIX PUTSTACK PUTS "\n\n"
  21. DROP
  22. RTN
  23.  
  24. LBL f   ; x^3 - (6 * x^2) + (11 * x) - 1
  25. DUP 3^ OVER 2^ 6* - SWAP 11* + 1-
  26. RTN
  27.  
  28. LBL fprime   ; (3*x^2) - (12*x) + 11
  29. DUP 2^ 3* SWAP 12* - 11+
  30. END
  31.